<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡排序</title>
</head>
<body>


<script>
    var y = [5,3,6,1,2,4];

    for (var i=0 ; i< y.length-1 ; i++){   //排序的次数

        for (var p=0 ; p< y.length-i-1 ; p++){
            
            //一趟确认一个数，数组长度减当前趟数就是剩下未确认的数需要比较的次数
            //因为j从0开始，所以还要再减1，或者理解为arr.length-(i+1)

            if(y[p] > y[p+1]){

                var wn = y[p];

                y[p] = y[p+1];

                y[p+1] = wn;

                console.log(y);
            }
        }
    }
</script>



</body>
</html>